package com.cskaoyan.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * 创建日期: 2022/05/05 20:06
 *
 * @author 孙豪骏
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdminListVoBean {

    private Integer id;

    private String username;

    private String password;

    private String lastLoginIp;

    private Date lastLoginTime;

    private String avatar;

    private Date addTime;

    private Date updateTime;

    private Boolean deleted;

    private String stringRoleIds;

    private Integer[] roleIds;
//把取到的这roleIds加工一下

    public void setStringRoleIds(String stringRoleIds) {
        if (stringRoleIds!=null) {
            String[] split = stringRoleIds.split(",");
            Integer[] integers = new Integer[split.length];
            for (int i = 0; i < split.length; i++) {
                integers[i] = Integer.parseInt(split[i].substring(1, 2));
            }
            this.roleIds = integers;
        }
        this.stringRoleIds=stringRoleIds;
    }

    public void setRoleIds(Integer[] roleIds) {
        String inside = "";
        if (roleIds != null) {

            for (int i = 0; i < roleIds.length; i++) {
                inside = inside + "[" + roleIds[i] + "]";
                if (i != roleIds.length - 1) {
                    inside = inside + ",";
                }
            }
        }
        this.stringRoleIds = inside;

        this.roleIds = roleIds;
    }
}